package JZOffer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

/**
 * @author Lw中
 * @date 2021/7/28 23:07
 */
public class Jz06 {

    // Jz06. 从尾到头打印链表
     public class ListNode {
         int val;
         ListNode next;
         ListNode(int x) {
             val = x;
         }
     }

    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<>();
//        int i = 0;
        while (head != null) {
            stack.push(head.val);
            head = head.next;
        }
        int size = stack.size();
//        int[] ints = new int[i];
        int[] ints = new int[size];
//        int j = 0;
//        while (!stack.isEmpty()) {
//            Integer pop = stack.pop();
//            ints[j++] = pop;
//        }
        for (int i = 0; i < size; i++) {
            Integer pop = stack.pop();
            ints[i] = pop;
        }
        return ints;
    }

}
